from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
# 用户表 执法人员信息
class UserInfo(AbstractUser):
    name = models.CharField(max_length=12, verbose_name="姓名")
    phone = models.CharField(max_length=11, unique=True, verbose_name="手机号")
    yhlb = (("1", "管理员"), ("2", "执法人员"))
    yhjb = (("1", "省级"), ("2", "市级"), ("3", "县级"))
    category = models.CharField(max_length=2, verbose_name="用户类别", choices=yhlb)  # 管理员用户
    level = models.CharField(max_length=2, verbose_name="用户级别", choices=yhjb,null=True,blank=True)  # 1省级2市级3县级，有用户级别就是审核过的，反之未审核
    organization = models.ForeignKey(to="Organization", verbose_name="单位", on_delete=models.CASCADE,null=True,blank=True,related_name="user",related_query_name="user")
    sfzhm=models.CharField(max_length=18, unique=True, verbose_name="身份证号码",null=True,blank=True)
    xl=(("", "---------"),("1", "博士研究生"), ("2", "硕士研究生"), ("3", "本科"), ("4", "专科"), ("5", "高中"), ("6", "高中以下"))
    xueli=models.CharField(max_length=2, verbose_name="学历",null=True,blank=True,choices=xl)
    junren=models.CharField(max_length=2, verbose_name="是否转业军人",null=True,blank=True,choices=(("1", "是"), ("2", "不是")),default='2')
    falv=models.CharField(max_length=2, verbose_name="是否法律专业",null=True,blank=True,choices=(("1", "是"), ("2", "不是")),default='2')
    zfz=models.CharField(max_length=2, verbose_name="是否持有执法证",null=True,blank=True,choices=(("1", "有"), ("2", "没有")),default='1')
    grbz=(("", "---------"),('1','公务员'),('2','参公'),('3','事业全供'),('4','事业全供（混编）'),('5','事业差供'),('6','自收自支'),('7','工勤人员'))
    bzlx=models.CharField(max_length=2,verbose_name="编制类型",null=True,blank=True,choices=grbz)
    gzbz=models.CharField(max_length=2,verbose_name="工资是否有保障",null=True,blank=True,choices=(("1", "有"), ("2", "没有")),default='1')
    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "用户"
        verbose_name_plural = verbose_name

# 用户所属的单位
class Organization(models.Model):
    title = models.CharField(max_length=18, verbose_name="单位名称")
    address = models.CharField(max_length=32, verbose_name="单位地址")
    fzr=models.CharField(max_length=8, verbose_name="负责人")
    lxr=models.CharField(max_length=8, verbose_name="联系人")
    phone1 = models.CharField(max_length=13, verbose_name="负责人电话",null=True,blank=True)
    phone2 = models.CharField(max_length=13, verbose_name="联系人电话",null=True,blank=True)
    bianzhi=models.IntegerField(verbose_name="编批人数",null=True,blank=True)
    gaopei=models.CharField(max_length=2, verbose_name="是否高配", choices=(("1", "是"), ("2", "否")),default="2")
    xingzhengquhua = models.ForeignKey("Xingzhengquhua", verbose_name="行政区划",null=True,blank=True ,on_delete=models.CASCADE)
    sj=models.ForeignKey('self',on_delete=models.SET_NULL,verbose_name='上级部门',null=True,blank=True)
    dw_xz=(('1', '行政机关内设机构'),('2', '独立行政单位'), ('3', '全供事业单位'), ('4', '差供事业事业单位'), ('5', '自收自支事业单位'))
    dwxz=models.CharField(max_length=2, verbose_name="单位性质",choices=dw_xz,null=True,blank=True)
    che = models.IntegerField(verbose_name='执法车辆数',null=True,blank=True)
    jingfei = models.DecimalField(verbose_name='执法经费（万元）', max_digits=5, decimal_places=2,null=True,blank=True)



    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "单位"
        verbose_name_plural = verbose_name

# 行政区划表
class Xingzhengquhua(models.Model):
    code=models.CharField(max_length=10, verbose_name="区划代码")
    sheng = models.CharField(max_length=10, verbose_name="省")
    shi = models.CharField(max_length=10, verbose_name="市")
    xian = models.CharField(max_length=10, verbose_name="县")

    def __str__(self):
        return self.sheng + self.shi + self.xian

    class Meta:
        verbose_name = "行政区划表"
        verbose_name_plural = verbose_name


